<template>
	<view :style="colorStyle">
		<!-- <goodsCate1 v-if="category == 1" ref="classOne" :isNew="isNew"></goodsCate1> -->
		<!-- <goodsCate2 v-if="category == 2" ref="classTwo" :isNew="isNew" @jumpIndex="jumpIndex"></goodsCate2> -->
		<!-- <goodsCate3 v-if="category == 3" :defaultIndex="defaultIndex" :authenticate_type="authenticate_type" :close_recharge="close_recharge" ref="classThree" :isNew="isNew" @jumpIndex="jumpIndex"></goodsCate3> -->
		<goodsCate3 :defaultIndex="defaultIndex" :authenticate_type="authenticate_type" :close_recharge="close_recharge" ref="classThree" :isNew="isNew" @jumpIndex="jumpIndex"></goodsCate3>
		<pageFooter></pageFooter>
	</view>
</template>

<script>
import {getUserInfo} from '@/api/user.js';
import pageFooter from '@/components/pageFooter/index.vue'
import colors from '@/mixins/color';
// 释放代码体积
// import goodsCate1 from './goods_cate1';
// import goodsCate2 from './goods_cate2';
import goodsCate3 from './goods_cate3';
import { colorChange } from '@/api/api.js';
import { mapGetters } from 'vuex';
import { getCategoryVersion } from '@/api/public.js';
import tabBar from '@/pages/index/visualization/components/tabBar.vue';
export default {
	computed: mapGetters(['isLogin', 'uid']),
	components: {
		// goodsCate1,
		// goodsCate2,
		goodsCate3,
		tabBar,
		pageFooter
	},
	mixins: [colors],
	data() {
		return {
			category: '',
			is_diy: uni.getStorageSync('is_diy'),
			status: 0,
			version: '',
			isNew: false,
			authenticate_type:0,
			close_recharge:1,
			defaultIndex: 0
		};
	},
	onLoad() {
		if(this.isLogin) this.getUserInfo();
		
		const i = uni.getStorageSync('goods_cate_index')
		if(i) {
			uni.removeStorageSync('goods_cate_index')
			this.defaultIndex = Number(i)
		}
	},
	onReady() {},
	onShow() {
		this.getCategoryVersion();
	},
	methods: {
		/**
		 * 获取是否已认证
		 */
		getUserInfo: function() {
			let that = this;
			getUserInfo().then(res => {
				const data = res.data
				this.authenticate_type=data.authenticate_type
				this.close_recharge=data.close_recharge//是否隐藏认证入口，支付审核使用
			});
		},
		getCategoryVersion() {
			uni.$emit('uploadFooter');
			getCategoryVersion().then((res) => {
				if (!uni.getStorageSync('CAT_VERSION') || res.data.version != uni.getStorageSync('CAT_VERSION')) {
					this.isNew = !this.isNew;
					uni.setStorageSync('CAT_VERSION', res.data.version);
				} else {
					// this.isNew = false
				}
				this.classStyle();
			});
		},
		jumpIndex() {
			// uni.reLaunch({
			// 	url: '/pages/index/index'
			// })
		},
		classStyle() {
			colorChange('category').then((res) => {
				let status = res.data.status;
				this.category = status;
				uni.setStorageSync('is_diy', res.data.is_diy);
				this.status = res.data.status;
				this.$nextTick((e) => {
					if (this.status == 2 || this.status == 3) {
						uni.hideTabBar();
					} else if (this.status == 1) {
						this.$refs.classOne.is_diy = res.data.is_diy;
						this.$refs.classOne.getNav();
					}
					if (status == 2) {
						if (this.isLogin) {
							this.$refs.classTwo.getCartNum();
							this.$refs.classTwo.getCartList(1);
						}
						// this.$refs.classTwo.getAllCategory()
					}
					if (status == 3) {
						if (this.isLogin) {
							this.$refs.classThree.getCartNum();
							this.$refs.classThree.getCartList(1);
							this.$refs.classThree.tempArr = [];
							this.$refs.classThree.loadend = false;
							this.$refs.classThree.page = 1;
							// this.$refs.classThree.productslist();
						}
						this.$refs.classThree.getAllCategory(1)
					}
					if (status == 2 || status == 3) {
						uni.hideTabBar();
					} else {
						if (!this.is_diy) {
							uni.hideTabBar();
						} else {
						}
						this.$refs.classOne.getNav();
					}
				});
			});
		}
	},
	onReachBottom: function () {
		if (this.category == 2) {
			this.$refs.classTwo.productslist();
		}
		if (this.category == 3) {
			this.$refs.classThree.productslist();
		}
	}
};
</script>
<style scoped lang="scss">
::v-deep.mask {
	z-index: 99;
}
</style>
